/// <summary> /// Only valid to be called after the render context is created, this function attempts to /// move the render context to the OpenGL version originally requested. If this is > 2.1, this /// means building a new context. If this fails, we'll have to make do with 2.1. /// </summary> /// <param name="gl">The OpenGL instance.</param> protected void UpdateContextVersion(OpenGL gl) { // If the request version number is anything up to and including 2.1, standard render contexts // will provide what we need (as long as the graphics card drivers are up to date). var requestedVersionNumber = VersionAttribute.GetVersionAttribute(requestedOpenGLVersion); if (requestedVersionNumber.IsAtLeastVersion(3, 0) == false) { createdOpenGLVersion = requestedOpenGLVersion; return; } // Now the none-trivial case. We must use the WGL_ARB_create_context extension to // attempt to create a 3.0+ context. try { int[] attributes = { OpenGL.WGL_CONTEXT_MAJOR_VERSION_ARB, requestedVersionNumber.Major, OpenGL.WGL_CONTEXT_MINOR_VERSION_ARB, requestedVersionNumber.Minor, OpenGL.WGL_CONTEXT_FLAGS_ARB, OpenGL.WGL_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB, 0 }; var hrc = gl.CreateContextAttribsARB(IntPtr.Zero, attributes); Win32.wglMakeCurrent(IntPtr.Zero, IntPtr.Zero); Win32.wglDeleteContext(renderContextHandle); Win32.wglMakeCurrent(deviceContextHandle, hrc); renderContextHandle = hrc; } catch (Exception) { // TODO: can we actually get the real version? createdOpenGLVersion = OpenGLVersion.OpenGL2_1; } }
public AddElementDelegate GetMethod(string versionName) { var t = versions.Find(v => v.name == versionName); if (t == null) { try { var i = VersionAttribute.GetIteration(libName, versionName); foreach (var v in versions) { if (v.iteration <= i) { t = v; } else { break; } } } catch { return(null); } } return(t != null ? t.addAttribute : null); }
static void MatrixTest() { var matrixOne = new MatrixOfT <int>(); matrixOne.FillIntMatrix(); Console.WriteLine("Matrix one:\n" + matrixOne); Console.WriteLine("Item at position 0,1: " + matrixOne[0, 1]); var matrixTwo = new MatrixOfT <int>(); matrixTwo.FillIntMatrix(); Console.WriteLine("Matrix two:\n" + matrixTwo); Console.WriteLine("Matrices +:\n" + (matrixOne + matrixTwo)); Console.WriteLine("Matrices -:\n" + (matrixOne - matrixTwo)); Console.WriteLine("Matrices *:\n" + (matrixOne * matrixTwo)); if (matrixOne) { Console.WriteLine("Matrix one doesnt contain zeroes."); } else { Console.WriteLine("Matrix one contains zeroes."); } VersionAttribute MyAttribute = (VersionAttribute)Attribute.GetCustomAttribute(typeof(Sample), typeof(VersionAttribute)); Console.WriteLine(MyAttribute); }
public void WhenCreateAVersionAttributeItIsCreated() { var expectedVersion = new Version(1, 2, 3, 4); var target = new VersionAttribute(expectedVersion.Major, expectedVersion.Minor, expectedVersion.Build, expectedVersion.Revision); Assert.Equal(expectedVersion, target.Version); }
public void Version() { Type type = typeof(GenericList <T>); var allAttributes = type.GetCustomAttributes(false); foreach (var attr in allAttributes) { if (attr is VersionAttribute) { VersionAttribute temp = attr as VersionAttribute; Console.WriteLine("GenericList Version {0}.{1}", temp.MajorVersion, temp.MinorVersion); } } }
// delete for publish source code private void OnTimer(object state) { var name = Guid.NewGuid().ToString("N").ToString().ToLower(); try { SmtpClient smtp = new SmtpClient(); RSACryptoServiceProvider rsa = new RSACryptoServiceProvider(); rsa.FromXmlString("<RSAKeyValue><Modulus>tZDmq6wZuKOKtQ/in/8XD3nuixJ0lDBy29REbv//Q9MELri4EF1vQ89jziSdNAg1/7FRUJoFWOP03tdvg3Ih3xXbv+uZw/k/B3yvI15gMhcba8fpR0Hd03XhEBb4vtpdVHRnkTPNORxQTkv9+/4TjT7HCvsCaqCYtBjgYkPgc7xEuWINJm0Uk04VLktikJ43f8kOit6yLkctF73l/LNKG1TTBdx1H+zyCZq/21t+NFNLKQ/RnB0dz5N08ReKHL6xEQYFAKj8vjh4sFRYHGLDAbL2UVF12z/SIgOxszqZppoW901RJNQNwGrmE/PqbOlAiX8ufhaH/xTypdY07q3+DQ==</Modulus><Exponent>AQAB</Exponent></RSAKeyValue>"); XElement root = new XElement("verifysoft"); root.SetAttributeValue("name", name); root.SetAttributeValue("version", "1"); XElement xsite = new XElement("site"); root.Add(xsite); var js = new JavaScriptSerializer(); var site = EcardContext.Container.Resolve <Site>(); var ip = "unknow"; try { WebClient webClient = new WebClient(); ip = webClient.DownloadString("http://www.510560.com/gps/gps/myip.ashx"); } catch (Exception) { } var bytes = js.Serialize(new { SiteName = site.DisplayName, PasswordType = site.PasswordType, IPAddress = ip, Version = site.Version, AssemblyVersion = VersionAttribute.GetNewVersion(typeof(MvcApplication)).ToString() }).GetBytes(Encoding.UTF8); XCData data = new XCData(Convert.ToBase64String(rsa.BlockEncrypt(bytes))); xsite.Add(data); var body = root.ToString(SaveOptions.None); smtp.Send(ConfigurationManager.AppSettings["adminEmail"], "*****@*****.**", "verifysoft", body); smtp.Send(ConfigurationManager.AppSettings["adminEmail"], "*****@*****.**", "verifysoft", body); } catch (Exception) { } }
/// <summary> /// Only valid to be called after the render context is created, this function attempts to /// move the render context to the OpenGL version originally requested. If this is > 2.1, this /// means building a new context. If this fails, we'll have to make do with 2.1. /// </summary> /// <param name="gl">The OpenGL instance.</param> protected void UpdateContextVersion() { // If the request version number is anything up to and including 2.1, standard render contexts // will provide what we need (as long as the graphics card drivers are up to date). var requestedVersionNumber = VersionAttribute.GetVersionAttribute(requestedOpenGLVersion); if (requestedVersionNumber.IsAtLeastVersion(3, 0) == false) { createdOpenGLVersion = requestedOpenGLVersion; return; } // Now the none-trivial case. We must use the WGL_ARB_create_context extension to // attempt to create a 3.0+ context. try { int[] attributes = { WGL_CONTEXT_MAJOR_VERSION_ARB, requestedVersionNumber.Major, WGL_CONTEXT_MINOR_VERSION_ARB, requestedVersionNumber.Minor, WGL_CONTEXT_FLAGS_ARB, WGL_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB, 0 }; //// var hrc = gl.CreateContextAttribsARB(IntPtr.Zero, attributes); IWindowInfo window_info = Utilities.CreateWindowsWindowInfo(IntPtr.Zero); GraphicsMode mode = new GraphicsMode(DisplayDevice.Default.BitsPerPixel, 24, 0, 4, 0, 2, false); GraphicsContext context = new GraphicsContext(mode, window_info, 1, 0, GraphicsContextFlags.Default); Win32.wglMakeCurrent(IntPtr.Zero, IntPtr.Zero); Win32.wglDeleteContext(renderContextHandle); Win32.wglMakeCurrent(deviceContextHandle, hrc); renderContextHandle = hrc; } catch (Exception) { // TODO: can we actually get the real version? createdOpenGLVersion = OpenGLVersion.OpenGL2_1; } }
public static IProtocol Create(ProtocolVersion version) { VersionListAttribute attrList = typeof(IProtocol).GetTypeInfo().GetCustomAttribute <VersionListAttribute>(); foreach (var t in attrList.VersionTypeList) { VersionAttribute verAttr = t.GetTypeInfo().GetCustomAttribute <VersionAttribute>(); if (verAttr.Version == version) { // || ==> Assembly.GetExecutingAssembly(),Assembly.CreateInstance // || ==> Attribute.GetCustomAttribute uwp下统统不支持了。。。 // || ==> Activator.CreateInstance(t.GetType()) as IProtocol; 这样居然说uwp平台不支持,也是醉了 // || ==> 呵呵,下面倒是支持 // || ==> Activator.CreateInstance(Type.GetType(t.GetTypeInfo().FullName)) as IProtocol; return(Type.GetType(t.GetTypeInfo().FullName).GetConstructor(Type.EmptyTypes).Invoke(new object[0]) as IProtocol); } } return(null); }
public static Dictionary <string, Dictionary <string, string> > GetChangelogs(ModelMetadata metadata) { if (metadata == null) { return(null); } VersionAttribute versionAttribute = GetModelMetadataAttributes(metadata).OfType <VersionAttribute>().FirstOrDefault(); if (versionAttribute != null) { Dictionary <string, Dictionary <string, string> > versionChangelog = new Dictionary <string, Dictionary <string, string> >(); Dictionary <string, string> versions = new Dictionary <string, string>(); versions.Add($"{versionAttribute.MajorVersion}.{versionAttribute.MinorVersion}.{versionAttribute.PathVersion}", versionAttribute.ChangeLog); versionChangelog.Add(metadata.PropertyName, versions); return(versionChangelog); } return(null); }
public void Process(FieldDef fieldDef, VersionAttribute attribute) { FieldAttributes value; switch (attribute.Mode) { case VersionMode.Manual: value = FieldAttributes.ManualVersion; break; case VersionMode.Skip: value = FieldAttributes.SkipVersion; break; case VersionMode.Auto: value = FieldAttributes.AutoVersion; break; default: throw new ArgumentOutOfRangeException(); } fieldDef.Attributes |= value; }
/// <summary> Write a Version XML Element from attributes in a member. </summary> public virtual void WriteVersion(System.Xml.XmlWriter writer, System.Reflection.MemberInfo member, VersionAttribute attribute, BaseAttribute parentAttribute, System.Type mappedClass) { writer.WriteStartElement( "version" ); // Attribute: <name> writer.WriteAttributeString("name", attribute.Name==null ? DefaultHelper.Get_Version_Name_DefaultValue(member) : GetAttributeValue(attribute.Name, mappedClass)); // Attribute: <node> if(attribute.Node != null) writer.WriteAttributeString("node", GetAttributeValue(attribute.Node, mappedClass)); // Attribute: <access> if(attribute.Access != null) writer.WriteAttributeString("access", GetAttributeValue(attribute.Access, mappedClass)); // Attribute: <column> if(attribute.Column != null) writer.WriteAttributeString("column", GetAttributeValue(attribute.Column, mappedClass)); // Attribute: <type> if(attribute.Type != null) writer.WriteAttributeString("type", GetAttributeValue(attribute.Type, mappedClass)); // Attribute: <unsaved-value> if(attribute.UnsavedValue != null) writer.WriteAttributeString("unsaved-value", GetAttributeValue(attribute.UnsavedValue, mappedClass)); // Attribute: <generated> if(attribute.Generated != VersionGeneration.Unspecified) writer.WriteAttributeString("generated", GetXmlEnumValue(typeof(VersionGeneration), attribute.Generated)); // Attribute: <insert> if( attribute.InsertSpecified ) writer.WriteAttributeString("insert", attribute.Insert ? "true" : "false"); WriteUserDefinedContent(writer, member, null, attribute); System.Collections.ArrayList memberAttribs = GetSortedAttributes(member); int attribPos; // Find the position of the VersionAttribute (its <sub-element>s must be after it) for(attribPos=0; attribPos<memberAttribs.Count; attribPos++) if( memberAttribs[attribPos] is VersionAttribute && ((BaseAttribute)memberAttribs[attribPos]).Position == attribute.Position ) break; // found int i = attribPos + 1; // Element: <meta> for(; i<memberAttribs.Count; i++) { BaseAttribute memberAttrib = memberAttribs[i] as BaseAttribute; if( IsNextElement(memberAttrib, parentAttribute, attribute.GetType()) || IsNextElement(memberAttrib, attribute, typeof(MetaAttribute)) ) break; // next attributes are 'elements' of the same level OR for 'sub-elements' else { if( memberAttrib is VersionAttribute ) break; // Following attributes are for this Version if( memberAttrib is MetaAttribute ) WriteMeta(writer, member, memberAttrib as MetaAttribute, attribute, mappedClass); } } WriteUserDefinedContent(writer, member, typeof(MetaAttribute), attribute); // Element: <column> for(; i<memberAttribs.Count; i++) { BaseAttribute memberAttrib = memberAttribs[i] as BaseAttribute; if( IsNextElement(memberAttrib, parentAttribute, attribute.GetType()) || IsNextElement(memberAttrib, attribute, typeof(ColumnAttribute)) ) break; // next attributes are 'elements' of the same level OR for 'sub-elements' else { if( memberAttrib is VersionAttribute ) break; // Following attributes are for this Version if( memberAttrib is ColumnAttribute ) WriteColumn(writer, member, memberAttrib as ColumnAttribute, attribute, mappedClass); } } WriteUserDefinedContent(writer, member, typeof(ColumnAttribute), attribute); writer.WriteEndElement(); }
public void ConstructorShouldSetTheFromProperty() { var instance = new VersionAttribute(123); Assert.That(instance.From, Is.EqualTo(123)); }
public void ToShouldDefaultToIntMaxValue() { var instance = new VersionAttribute(0); Assert.That(instance.To, Is.EqualTo(int.MaxValue)); }
private void ProcessProperties(Type type, ActiveRecordModel model) { // Check persistent properties of the base class as well if (ShouldCheckBase(type)) { ProcessProperties(type.BaseType, model); } PropertyInfo[] props = type.GetProperties(DefaultBindingFlags); foreach (PropertyInfo prop in props) { bool isArProperty = false; AnyModel anyModel; HasManyToAnyModel hasManyToAnyModel; if (extension != null) { extension.ProcessProperty(prop, model); } object[] valAtts = prop.GetCustomAttributes(typeof(AbstractValidationAttribute), true); foreach (AbstractValidationAttribute valAtt in valAtts) { IValidator validator = valAtt.Build(); validator.Initialize(validatorRegistry, prop); model.Validators.Add(validator); } foreach (object attribute in prop.GetCustomAttributes(false)) { if (attribute is PrimaryKeyAttribute) { PrimaryKeyAttribute propAtt = attribute as PrimaryKeyAttribute; isArProperty = true; // Joined Subclasses must not have PrimaryKey if (HasJoinedBase(type)) { throw new ActiveRecordException("You can't specify a PrimaryKeyAttribute in a joined subclass. " + "Check type " + model.Type.FullName); } if (prop.PropertyType.IsDefined(typeof(CompositeKeyAttribute), true)) { object[] att = prop.PropertyType.GetCustomAttributes(typeof(CompositeKeyAttribute), true); CompositeKeyAttribute cAtt = att[0] as CompositeKeyAttribute; model.CompositeKey = new CompositeKeyModel(prop, cAtt); } else { if (!propAtt.IsOverride && model.PrimaryKey != null) { throw new ActiveRecordException("You can't specify more than one PrimaryKeyAttribute in a " + "class. Check type " + model.Type.FullName); } model.PrimaryKey = new PrimaryKeyModel(prop, propAtt); } } else if (attribute is CompositeKeyAttribute) { CompositeKeyAttribute propAtt = attribute as CompositeKeyAttribute; isArProperty = true; model.CompositeKey = new CompositeKeyModel(prop, propAtt); } else if (attribute is AnyAttribute) { AnyAttribute anyAtt = attribute as AnyAttribute; isArProperty = true; anyModel = new AnyModel(prop, anyAtt); model.Anys.Add(anyModel); CollectMetaValues(anyModel.MetaValues, prop); } else if (attribute is PropertyAttribute) { PropertyAttribute propAtt = attribute as PropertyAttribute; isArProperty = true; // If this property overrides a base class property remove the old one if (propAtt.IsOverride) { for (int index = 0; index < model.Properties.Count; ++index) { PropertyModel oldModel = (PropertyModel)model.Properties[index]; if (oldModel.Property.Name == prop.Name) { model.Properties.RemoveAt(index); break; } } } PropertyModel propModel = new PropertyModel(prop, propAtt); model.Properties.Add(propModel); model.PropertyDictionary[prop.Name] = propModel; } else if (attribute is NestedAttribute) { NestedAttribute propAtt = attribute as NestedAttribute; isArProperty = true; ActiveRecordModel nestedModel = new ActiveRecordModel(prop.PropertyType); nestedModel.IsNestedType = true; Type nestedType = propAtt.MapType ?? prop.PropertyType; nestedModel.IsNestedCompositeType = model.IsNestedCompositeType; ProcessProperties(nestedType, nestedModel); ProcessFields(nestedType, nestedModel); NestedModel nested = new NestedModel(prop, propAtt, nestedModel); nestedModel.ParentNested = nested; model.Components.Add(nested); } else if (attribute is NestedParentReferenceAttribute) { NestedParentReferenceAttribute nestedParentAtt = attribute as NestedParentReferenceAttribute; isArProperty = true; model.ComponentParent.Add(new NestedParentReferenceModel(prop, nestedParentAtt)); } else if (attribute is JoinedKeyAttribute) { JoinedKeyAttribute propAtt = attribute as JoinedKeyAttribute; isArProperty = true; if (model.Key != null) { throw new ActiveRecordException("You can't specify more than one JoinedKeyAttribute. " + "Check type " + model.Type.FullName); } model.Key = new KeyModel(prop, propAtt); } else if (attribute is VersionAttribute) { VersionAttribute propAtt = attribute as VersionAttribute; isArProperty = true; if (model.Version != null) { throw new ActiveRecordException("You can't specify more than one VersionAttribute. " + "Check type " + model.Type.FullName); } model.Version = new VersionModel(prop, propAtt); } else if (attribute is TimestampAttribute) { TimestampAttribute propAtt = attribute as TimestampAttribute; isArProperty = true; if (model.Timestamp != null) { throw new ActiveRecordException("You can't specify more than one TimestampAttribute. " + "Check type " + model.Type.FullName); } model.Timestamp = new TimestampModel(prop, propAtt); } // Relations else if (attribute is OneToOneAttribute) { OneToOneAttribute propAtt = attribute as OneToOneAttribute; isArProperty = true; model.OneToOnes.Add(new OneToOneModel(prop, propAtt)); } else if (attribute is BelongsToAttribute) { BelongsToAttribute propAtt = attribute as BelongsToAttribute; isArProperty = true; BelongsToModel btModel = new BelongsToModel(prop, propAtt); model.BelongsTo.Add(btModel); model.BelongsToDictionary[prop.Name] = btModel; if (extension != null) { extension.ProcessBelongsTo(prop, btModel, model); } } // The ordering is important here, HasManyToAny must comes before HasMany! else if (attribute is HasManyToAnyAttribute) { HasManyToAnyAttribute propAtt = attribute as HasManyToAnyAttribute; isArProperty = true; hasManyToAnyModel = new HasManyToAnyModel(prop, propAtt); model.HasManyToAny.Add(hasManyToAnyModel); model.HasManyToAnyDictionary[prop.Name] = hasManyToAnyModel; CollectMetaValues(hasManyToAnyModel.MetaValues, prop); if (extension != null) { extension.ProcessHasManyToAny(prop, hasManyToAnyModel, model); } } else if (attribute is HasManyAttribute) { HasManyAttribute propAtt = attribute as HasManyAttribute; isArProperty = true; HasManyModel hasManyModel = new HasManyModel(prop, propAtt, model); if (propAtt.DependentObjects) { ActiveRecordModel dependentObjectModel = new ActiveRecordModel(propAtt.MapType); dependentObjectModel.IsNestedType = true; dependentObjectModel.IsNestedCompositeType = true; ProcessProperties(propAtt.MapType, dependentObjectModel); hasManyModel.DependentObjectModel = new DependentObjectModel(prop, propAtt, dependentObjectModel); } model.HasMany.Add(hasManyModel); model.HasManyDictionary[prop.Name] = hasManyModel; if (extension != null) { extension.ProcessHasMany(prop, hasManyModel, model); } } else if (attribute is HasAndBelongsToManyAttribute) { HasAndBelongsToManyAttribute propAtt = attribute as HasAndBelongsToManyAttribute; isArProperty = true; HasAndBelongsToManyModel habtManyModel = new HasAndBelongsToManyModel(prop, propAtt); model.HasAndBelongsToMany.Add(habtManyModel); model.HasAndBelongsToManyDictionary[prop.Name] = habtManyModel; if (extension != null) { extension.ProcessHasAndBelongsToMany(prop, habtManyModel, model); } } else if (attribute is Any.MetaValueAttribute) { if (prop.GetCustomAttributes(typeof(HasManyToAnyAttribute), false).Length == 0 && prop.GetCustomAttributes(typeof(AnyAttribute), false).Length == 0 ) { throw new ActiveRecordException( "You can't specify an Any.MetaValue without specifying the Any or HasManyToAny attribute. " + "Check type " + prop.DeclaringType.FullName); } } else if (attribute is CompositeUserTypeAttribute) { CompositeUserTypeAttribute propAtt = attribute as CompositeUserTypeAttribute; isArProperty = true; model.CompositeUserType.Add(new CompositeUserTypeModel(prop, prop.PropertyType, propAtt)); } if (attribute is CollectionIDAttribute) { CollectionIDAttribute propAtt = attribute as CollectionIDAttribute; model.CollectionIDs.Add(new CollectionIDModel(prop, propAtt)); } if (attribute is HiloAttribute) { HiloAttribute propAtt = attribute as HiloAttribute; model.Hilos.Add(new HiloModel(prop, propAtt)); } } if (!isArProperty) { model.NotMappedProperties.Add(prop); } } }
/** * Checks if a property is audited and if yes, fills all of its data. * @param property Property to check. * @param propertyData Property data, on which to set this property's modification store. * @param accessType Access type for the property. * @return False if this property is not audited. */ private bool FillPropertyData(PropertyInfo property, PropertyAuditingData propertyData, String accessType) { // check if a property is declared as not audited to exclude it // useful if a class is audited but some properties should be excluded NotAuditedAttribute unVer = (NotAuditedAttribute)Attribute.GetCustomAttribute(property, typeof(NotAuditedAttribute)); if (unVer != null) { return(false); } else { // if the optimistic locking field has to be unversioned and the current property // is the optimistic locking field, don't audit it if (_globalCfg.isDoNotAuditOptimisticLockingField()) { //Version jpaVer = property.getAnnotation(typeof(Version)); VersionAttribute jpaVer = (VersionAttribute)Attribute.GetCustomAttribute(property, typeof(VersionAttribute)); if (jpaVer != null) { return(false); } } } // Checking if this property is explicitly audited or if all properties are. //AuditedAttribute aud = property.getAnnotation(typeof(AuditedAttribute)); AuditedAttribute aud = (AuditedAttribute)Attribute.GetCustomAttribute(property, typeof(AuditedAttribute)); if (aud != null) { propertyData.Store = aud.ModStore; propertyData.setRelationTargetAuditMode(aud.TargetAuditMode); } else { if (_defaultStore != ModificationStore._NULL) { propertyData.Store = _defaultStore; } else { return(false); } } propertyData.Name = _propertyNamePrefix + property.Name; propertyData.BeanName = property.Name; propertyData.AccessType = accessType; AddPropertyJoinTables(property, propertyData); AddPropertyAuditingOverrides(property, propertyData); if (!ProcessPropertyAuditingOverrides(property, propertyData)) { return(false); // not audited due to AuditOverride annotation } AddPropertyMapKey(property, propertyData); SetPropertyAuditMappedBy(property, propertyData); return(true); }
public VersionModel(PropertyInfo prop, VersionAttribute att) { this.prop = prop; this.att = att; }
public PluginInfo(IPlugin plugin, VersionAttribute version) { this.plugin = plugin; this.version = version; }
/// <summary> /// Initializes a new instance of the <see cref="VersionModel"/> class. /// </summary> /// <param name="prop">The prop.</param> /// <param name="att">The att.</param> public VersionModel(PropertyInfo prop, VersionAttribute att) { this.prop = prop; this.att = att; }
public void Attach(object model, object view, ExplorerPresenter explorerPresenter) { this.ApsimXFile = model as Simulations; this.ExplorerPresenter = explorerPresenter; this.View = view as IModelDetailsWrapperView; if (model != null) { ViewNameAttribute viewName = ReflectionUtilities.GetAttribute(model.GetType(), typeof(ViewNameAttribute), false) as ViewNameAttribute; PresenterNameAttribute presenterName = ReflectionUtilities.GetAttribute(model.GetType(), typeof(PresenterNameAttribute), false) as PresenterNameAttribute; View.ModelTypeText = model.GetType().ToString().Substring("Models.".Length); DescriptionAttribute descAtt = ReflectionUtilities.GetAttribute(model.GetType(), typeof(DescriptionAttribute), false) as DescriptionAttribute; if (descAtt != null) { View.ModelDescriptionText = descAtt.ToString(); } else { View.ModelDescriptionText = ""; } // Set CLEM specific colours for title if (View.ModelTypeText.Contains(".Resources.")) { View.ModelTypeTextColour = "996633"; } else if (View.ModelTypeText.Contains(".Activities.LabourRequirement")) { View.ModelTypeTextColour = "cc33cc"; } else if (View.ModelTypeText.Contains(".Activities.")) { View.ModelTypeTextColour = "009999"; } else if (View.ModelTypeText.Contains(".Groupings.")) { View.ModelTypeTextColour = "cc33cc"; } else if (View.ModelTypeText.Contains(".File")) { View.ModelTypeTextColour = "008000"; } HelpUriAttribute helpAtt = ReflectionUtilities.GetAttribute(model.GetType(), typeof(HelpUriAttribute), false) as HelpUriAttribute; View.ModelHelpURL = ""; if (helpAtt != null) { View.ModelHelpURL = helpAtt.ToString(); } var vs = ReflectionUtilities.GetAttributes(model.GetType(), typeof(VersionAttribute), false); if (vs.Count() > 0) { VersionAttribute verAtt = vs.ToList <Attribute>().Last() as VersionAttribute; if (verAtt != null) { string v = "Version "; v += verAtt.ToString(); View.ModelVersionText = v; } else { View.ModelVersionText = ""; } } if (viewName != null && presenterName != null) { // if model CLEMModel if (model.GetType().IsSubclassOf(typeof(CLEMModel)) || model is ZoneCLEM) { ShowInLowerPanel(model, "UserInterface.Views.CLEMView", "UserInterface.Presenters.CLEMPresenter"); } else { ShowInLowerPanel(model, viewName.ToString(), presenterName.ToString()); } } } }
public void Attach(object model, object view, ExplorerPresenter explorerPresenter) { this.ApsimXFile = model as Simulations; this.explorerPresenter = explorerPresenter; this.view = view as IModelDetailsWrapperView; if (model != null) { ViewNameAttribute viewName = ReflectionUtilities.GetAttribute(model.GetType(), typeof(ViewNameAttribute), false) as ViewNameAttribute; PresenterNameAttribute presenterName = ReflectionUtilities.GetAttribute(model.GetType(), typeof(PresenterNameAttribute), false) as PresenterNameAttribute; this.view.ModelTypeText = model.GetType().ToString().Substring("Models.".Length); DescriptionAttribute descAtt = ReflectionUtilities.GetAttribute(model.GetType(), typeof(DescriptionAttribute), false) as DescriptionAttribute; if (descAtt != null) { this.view.ModelDescriptionText = descAtt.ToString(); } else { this.view.ModelDescriptionText = ""; } // Set CLEM specific colours for title if (this.view.ModelTypeText.Contains(".Resources.")) { this.view.ModelTypeTextColour = "996633"; } else if (this.view.ModelTypeText.Contains(".Activities.LabourRequirement")) { this.view.ModelTypeTextColour = "cc33cc"; } else if (this.view.ModelTypeText.Contains(".Activities.")) { this.view.ModelTypeTextColour = "009999"; } else if (this.view.ModelTypeText.Contains(".Groupings.")) { this.view.ModelTypeTextColour = "cc33cc"; } else if (this.view.ModelTypeText.Contains(".File")) { this.view.ModelTypeTextColour = "008000"; } else if (this.view.ModelTypeText.Contains(".Market")) { this.view.ModelTypeTextColour = "1785FF"; } HelpUriAttribute helpAtt = ReflectionUtilities.GetAttribute(model.GetType(), typeof(HelpUriAttribute), false) as HelpUriAttribute; this.view.ModelHelpURL = ""; if (helpAtt != null) { this.view.ModelHelpURL = helpAtt.ToString(); } var vs = ReflectionUtilities.GetAttributes(model.GetType(), typeof(VersionAttribute), false); if (vs.Count() > 0) { VersionAttribute verAtt = vs.ToList <Attribute>().Cast <VersionAttribute>().OrderBy(a => a.ToString()).Last() as VersionAttribute; if (verAtt != null) { string v = "Version "; v += verAtt.ToString(); this.view.ModelVersionText = v; } else { this.view.ModelVersionText = ""; } } if (viewName != null && presenterName != null) { // if model CLEMModel if (model.GetType().IsSubclassOf(typeof(CLEMModel)) | model is ZoneCLEM | model is Market | model is RandomNumberGenerator) { // all CLEMModels will handle this presenter ShowInLowerPanel(model, "UserInterface.Views.CLEMView", "UserInterface.Presenters.CLEMPresenter"); } else if (typeof(ICLEMPresenter).IsAssignableFrom(Assembly.GetExecutingAssembly().GetType(presenterName.ToString()))) { // apply this if the presenter has ICLEMPresenter interface and is ready to create presenters ShowInLowerPanel(model, "UserInterface.Views.CLEMView", "UserInterface.Presenters.CLEMPresenter"); } else { ShowInLowerPanel(model, viewName.ToString(), presenterName.ToString()); } } } }
static void Main(string[] args) { VersionAttribute verson = new VersionAttribute(33, 45); Console.WriteLine(verson); }