本文整理汇总了C#中System.Attribute类的典型用法代码示例。如果您正苦于以下问题:C# Attribute类的具体用法?C# Attribute怎么用?C# Attribute使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Attribute类属于System命名空间,在下文中一共展示了Attribute类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
public static int Main()
{
Attribute[]
attr_array
=
new
Attribute
[1];
object
obj
=
(object)
attr_array;
object
[]
obj_array
=
(object[])
obj;
obj_array
=
obj
as
object[];
if
(obj_array
==
null)
return
1;
return
0;
}
示例2: GetProperties
/// <summary>
/// Returns the property descriptors for this instance.
/// </summary>
public override PropertyDescriptorCollection GetProperties(ITypeDescriptorContext context, object value, Attribute[] attributes)
{
Guard.NotNull(() => context, context);
var descriptors = base.GetProperties(context, value, attributes).Cast<PropertyDescriptor>();
// Remove descriptors for the data type of this property (string)
descriptors = descriptors.Where(descriptor => descriptor.ComponentType != typeof(string));
// Get the model element being described
var selection = context.Instance;
ModelElement mel = selection as ModelElement;
var pel = selection as PresentationElement;
if (pel != null)
{
mel = pel.Subject;
}
var element = ExtensionElement.GetExtension<ArtifactExtension>(mel);
if (element != null)
{
// Copy descriptors from owner (make Browsable)
var descriptor1 = new DelegatingPropertyDescriptor(element, TypedDescriptor.CreateProperty(element, extension => extension.OnArtifactActivation),
new BrowsableAttribute(true), new DefaultValueAttribute(element.GetPropertyDefaultValue<ArtifactExtension, ArtifactActivatedAction>(e => e.OnArtifactActivation)));
var descriptor2 = new DelegatingPropertyDescriptor(element, TypedDescriptor.CreateProperty(element, extension => extension.OnArtifactDeletion),
new BrowsableAttribute(true), new DefaultValueAttribute(element.GetPropertyDefaultValue<ArtifactExtension, ArtifactDeletedAction>(e => e.OnArtifactDeletion)));
descriptors = descriptors.Concat(new[] { descriptor1, descriptor2 });
}
return new PropertyDescriptorCollection(descriptors.ToArray());
}
示例3: IsPlatformSupported
/// <summary>
/// Tests to determine if the current platform is supported
/// based on a platform attribute.
/// </summary>
/// <param name="platformAttribute">The attribute to examine</param>
/// <returns></returns>
public bool IsPlatformSupported( Attribute platformAttribute )
{
//Use reflection to avoid dependency on a particular framework version
string include = (string)Reflect.GetPropertyValue(
platformAttribute, "Include",
BindingFlags.Public | BindingFlags.Instance );
string exclude = (string)Reflect.GetPropertyValue(
platformAttribute, "Exclude",
BindingFlags.Public | BindingFlags.Instance );
try
{
if (include != null && !IsPlatformSupported(include))
{
reason = string.Format("Only supported on {0}", include);
return false;
}
if (exclude != null && IsPlatformSupported(exclude))
{
reason = string.Format("Not supported on {0}", exclude);
return false;
}
}
catch( ArgumentException ex )
{
reason = string.Format( "Invalid platform name: {0}", ex.ParamName );
return false;
}
return true;
}
示例4: GetProperties
public override PropertyDescriptorCollection GetProperties(Attribute[] attributes)
{
var props = base.GetProperties(attributes);
var allProperties = new List<PropertyDescriptor>();
TypeProviderHelper.AddDefaultProperties(allProperties,props);
TypeProviderHelper.AddTextBasedProperties(allProperties,props);
var prop = props.Find("Text", true);
allProperties.Add(prop);
prop = props.Find("DrawBorder",true);
allProperties.Add(prop);
prop = props.Find("FrameColor",true);
allProperties.Add(prop);
prop = props.Find("ForeColor",true);
allProperties.Add(prop);
prop = props.Find("Visible",true);
allProperties.Add(prop);
prop = props.Find("Expression",true);
allProperties.Add(prop);
return new PropertyDescriptorCollection(allProperties.ToArray());
}
示例5: ExcludeKnownAttrsFilter
public static bool ExcludeKnownAttrsFilter(Attribute x)
{
return x.GetType() != typeof(RouteAttribute)
&& x.GetType() != typeof(DescriptionAttribute)
&& x.GetType().Name != "DataContractAttribute" //Type equality issues with Mono .NET 3.5/4
&& x.GetType().Name != "DataMemberAttribute";
}
示例6: ApplyAttribute
// public methods
/// <summary>
/// Apply an attribute to these serialization options and modify the options accordingly.
/// </summary>
/// <param name="serializer">The serializer that these serialization options are for.</param>
/// <param name="attribute">The serialization options attribute.</param>
public override void ApplyAttribute(IBsonSerializer serializer, Attribute attribute)
{
EnsureNotFrozen();
var itemSerializer = serializer.GetItemSerializationInfo().Serializer;
if (_itemSerializationOptions == null)
{
var itemDefaultSerializationOptions = itemSerializer.GetDefaultSerializationOptions();
// special case for legacy collections: allow BsonRepresentation on object
if (itemDefaultSerializationOptions == null &&
(serializer.GetType() == typeof(EnumerableSerializer) || serializer.GetType() == typeof(QueueSerializer) || serializer.GetType() == typeof(StackSerializer)) &&
attribute.GetType() == typeof(BsonRepresentationAttribute))
{
itemDefaultSerializationOptions = new RepresentationSerializationOptions(BsonType.Null); // will be modified later by ApplyAttribute
}
if (itemDefaultSerializationOptions == null)
{
var message = string.Format(
"A serialization options attribute of type {0} cannot be used when the serializer is of type {1} and the item serializer is of type {2}.",
BsonUtils.GetFriendlyTypeName(attribute.GetType()),
BsonUtils.GetFriendlyTypeName(serializer.GetType()),
BsonUtils.GetFriendlyTypeName(itemSerializer.GetType()));
throw new NotSupportedException(message);
}
_itemSerializationOptions = itemDefaultSerializationOptions.Clone();
}
_itemSerializationOptions.ApplyAttribute(itemSerializer, attribute);
}
示例7: AddProperty
public PropertyDescriptorCollection AddProperty(PropertyDescriptorCollection pdc, string propertyName, Type propertyType, TypeConverter converter,
Attribute[] attributes)
{
List<PropertyDescriptor> properties = new List<PropertyDescriptor>(pdc.Count);
for (int i = 0; i < pdc.Count; i++)
{
PropertyDescriptor pd = pdc[i];
if (pd.Name != propertyName)
{
properties.Add(pd);
}
}
InstanceSavePropertyDescriptor ppd = new InstanceSavePropertyDescriptor(
propertyName, propertyType, attributes);
ppd.TypeConverter = converter;
properties.Add(ppd);
//PropertyDescriptor propertyDescriptor;
return new PropertyDescriptorCollection(properties.ToArray());
}
示例8: PreFilterProperties
protected override void PreFilterProperties(IDictionary properties)
{
base.PreFilterProperties(properties);
string[] ta = new string[] { "PasswordChar" };
Attribute[] aa = new Attribute[0];
for (int num1 = 0; num1 < ta.Length; num1++)
{
PropertyDescriptor desc = (PropertyDescriptor)properties[ta[num1]];
if (desc != null)
{
properties[ta[num1]] = TypeDescriptor.CreateProperty(typeof(TextBoxXDesigner), desc, aa);
}
}
ta = new string[] { "Text" };
aa = new Attribute[0];
for (int num1 = 0; num1 < ta.Length; num1++)
{
PropertyDescriptor desc = (PropertyDescriptor)properties[ta[num1]];
if (desc != null)
{
properties[ta[num1]] = TypeDescriptor.CreateProperty(typeof(TextBoxXDesigner), desc, aa);
}
}
}
示例9: GetProperties
public override PropertyDescriptorCollection GetProperties(ITypeDescriptorContext context, object component, Attribute[] attrs)
{
List<PropertyDescriptor> propList = new List<PropertyDescriptor>();
PropertyInfo interactionsProperty = component.GetType().GetProperty("Interactions");
if (interactionsProperty != null)
{
Interactions interactions = (Interactions)interactionsProperty.GetValue(component, null);
for (int i = 0; i < interactions.FunctionSuffixes.Length; i++)
{
string eventName = interactions.DisplayNames[i];
if (UpdateEventName != null)
{
eventName = UpdateEventName(eventName);
}
if (eventName.IndexOf("$$") < 0)
{
// Only add the event if the cursor mode exists
propList.Add(new InteractionPropertyDescriptor(component, i, interactions.FunctionSuffixes[i], eventName));
}
}
}
return new PropertyDescriptorCollection(propList.ToArray());
}
示例10: LambdaPropertyDescriptor
public LambdaPropertyDescriptor(string propertyName, Type propertyType, Attribute[] attrs,
Type componentType = null)
: base(propertyName, attrs)
{
_propertyType = propertyType;
_componentType = componentType;
}
示例11: GetProperties
public override PropertyDescriptorCollection GetProperties(Attribute[] attributes)
{
PropertyDescriptorCollection props = base.GetProperties(attributes);
List<PropertyDescriptor> allProperties = new List<PropertyDescriptor>();
TypeProviderHelper.AddDefaultProperties(allProperties,props);
PropertyDescriptor prop = null;
prop = props.Find("DrawBorder",true);
allProperties.Add(prop);
prop = props.Find("ForeColor",true);
allProperties.Add(prop);
prop = props.Find("Visible",true);
allProperties.Add(prop);
prop = props.Find("FrameColor",true);
allProperties.Add(prop);
prop = props.Find("Controls",true);
allProperties.Add(prop);
// prop = props.Find("AlternateBackColor",true);
// allProperties.Add(prop);
//
// prop = props.Find("ChangeBackColorEveryNRow",true);
// allProperties.Add(prop);
return new PropertyDescriptorCollection(allProperties.ToArray());
}
示例12: GetProperties
public override PropertyDescriptorCollection GetProperties(Attribute[] attributes)
{
PropertyDescriptorCollection props = base.GetProperties(attributes);
List<PropertyDescriptor> allProperties = new List<PropertyDescriptor>();
DesignerHelper.AddDefaultProperties(allProperties,props);
PropertyDescriptor prop = null;
prop = props.Find("ForeColor",true);
allProperties.Add(prop);
prop = props.Find("FromPoint",true);
allProperties.Add(prop);
prop = props.Find("ToPoint",true);
allProperties.Add(prop);
prop = props.Find("StartLineCap",true);
allProperties.Add(prop);
prop = props.Find("EndLineCap",true);
allProperties.Add(prop);
prop = props.Find("dashLineCap",true);
allProperties.Add(prop);
prop = props.Find("DashStyle",true);
allProperties.Add(prop);
prop = props.Find("Thickness",true);
allProperties.Add(prop);
return new PropertyDescriptorCollection(allProperties.ToArray());
}
示例13: CreateObject
private JObject CreateObject(Type type, Attribute[] attributes, object instance)
{
var jObject = CreateEmptyObject(instance);
var properties = new JArray();
jObject.Add("properties", properties);
var hypermediaObject = instance as HypermediaType ?? new HypermediaObject();
var addedProperties = new Dictionary<string, string>();
foreach (var propertyInfo in type.GetProperties()) {
if (PropertyIgnoreList.Contains(propertyInfo.Name)) {
continue;
}
var property = GetProperty(propertyInfo, instance, hypermediaObject);
addedProperties.Add(propertyInfo.Name, propertyInfo.Name);
property.Add("name", ToCamelCase(propertyInfo.Name));
properties.Add(property);
}
foreach (var hypermediaProperty in hypermediaObject.Properties) {
if (addedProperties.ContainsKey(hypermediaProperty.Key)) {
continue;
}
var property = SerializeValueType(hypermediaProperty.Value);
property.Add("name", ToCamelCase(hypermediaProperty.Key));
properties.Add(property);
}
return jObject;
}
示例14: GetProperties
public override PropertyDescriptorCollection GetProperties(ITypeDescriptorContext context, object value, Attribute[] attributes)
{
//var cols = base.GetProperties();
var props = new PropertyDescriptorCollection(null);
foreach (FieldInfo fi in value.GetType().GetFields())
{
var prop = new WsdlFieldDescriptor(fi, attributes);
props.Add(prop);
if (fi.FieldType.BaseType.FullName == "System.Array")
{
TypeDescriptor.AddAttributes(fi.FieldType, new TypeConverterAttribute(typeof(ArrayConverter)));
Type elemType = fi.FieldType.GetElementType();
TypeDescriptorModifier.modifyType(elemType);
}
else if (fi.FieldType.BaseType.FullName == "System.Enum")
{
}
else
{
TypeDescriptorModifier.modifyType(fi.FieldType);
}
}
if (props.Count > 0)
return props;
return base.GetProperties(context, value, attributes);
}
示例15: GetProperties
public override PropertyDescriptorCollection GetProperties(Attribute[] attributes)
{
var pdl = propertyDescriptorList.FindAll(pd => pd.Attributes.Contains(attributes));
PreProcess(pdl);
var pdcReturn = new PropertyDescriptorCollection(pdl.ToArray());
return pdcReturn;
}